package huang.homework12;

public class Bankcontrol {
		//存款方法
		public boolean addFund(Person person,double fund)
		{
			Dao ps=new Dao();
			//存款语句生成方法;
			String sql="update account set fund=fund+"+fund+"where accountname="+person.getAccount().getAccountName()+"";
			boolean result=ps.update(sql);
			System.out.println(result);
			if(result){
				System.out.println("存款成功！！");
				
			}else{
				System.out.println("存款失败！！");
			}	
			return result;
		}
		//转账方法
		public boolean exchangeFund(Person person1,double fund,Person person2)
		{	
			Dao ps=new Dao();
			//转账语句生成;
			String sql1="update account set fund=fund-"+fund+"where accountname="+person1.getAccount().getAccountName()+"";
			String sql2="update account set fund=fund+"+fund+"where accountname="+person2.getAccount().getAccountName()+"";
			if(ps.update(sql1)&&ps.update(sql2)){
				System.out.println("转账成功！！");
			}
			else{
				System.out.println("转账失败！！");
			}
			return ps.update(sql1)&&ps.update(sql2);
		}
		//注销个人账户方法
		public boolean logout(Person person ){
			Dao ps=new Dao();
			//注销语句生成;
			String sql="delete from account where accountname="+person.getAccount().getAccountName()+"";
			if(ps.delete(sql)){
				System.out.println("注销成功！！");
			}
			else{
				System.out.println("注销失败！！");
			}
			return ps.delete(sql);
		}
		
}
